package com.bawei.controller;

import com.alibaba.fastjson.JSONObject;
import com.bawei.pojo.Order;
import com.bawei.pojo.User;
import com.bawei.service.OrderService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    //商品秒杀列表
    @RequestMapping("/orderList")
    public String orderList(Model model){
        List<Order> list = orderService.orderList();
        model.addAttribute("list",list);
        return "orderList";
    }

    //商品秒杀回显
    @RequestMapping("/echo")
    @ResponseBody
    public Order echo(@RequestParam Integer middleId){
        return orderService.echo(middleId);
    }

    //跳转至商品秒杀详情页面
    @RequestMapping("/goGoods")
    public String goGoods(){
        return "goods";
    }

    //倒计时处理
    @RequestMapping("/daojishi")
    public String daojishi(@RequestParam Long endTime){
        Date date = new Date();
        long time = date.getTime();
        String t = String.valueOf(endTime-time);
        return String.valueOf(t);
    }

}
